﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using eCRAM.Dao;
using Microsoft.Practices.Unity;
using eCRAM.Model;

namespace eCRAM.Bll
{
    public class CramManager : ICramManager
    {
        [Dependency]
        public ICramRepository CramRepository { get; set; }
        
        [Dependency]
        public CramLineRepository CramLineRepository { get; set; }

        public Cram FindCram(Guid userId, int month, int year)
        {
            return CramRepository.FindCram(userId, month, year);
        }

        public void InsertCram(Cram cram)
        {
            CramRepository.Create(cram);
        }


        public void InsertCramLine(CramLine cramLine)
        {
            CramLineRepository.Create(cramLine);
        }

        public void SaveOrUpDateCram(Cram cram)
        {
            if (cram.Id == null)
            {
                CramRepository.Create(cram);
            }
            else
            {
                CramRepository.SubmitChanges();
            }
        }
    }
}
